package com.enjoyor.soa.traffic.core.efoms.service.impl;

import com.enjoyor.soa.traffic.core.efoms.domain.EvalItemInfo;
import com.enjoyor.soa.traffic.core.efoms.mapper.IEvalItemInfoMapper;
import com.enjoyor.soa.traffic.core.efoms.service.IEvalItemInfoService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@Transactional
public class EvalItemInfoService implements IEvalItemInfoService {

    @Autowired
    private IEvalItemInfoMapper evalItemInfoMapper;

    @Autowired
    private IPubLogMapper pubLogMapper;

    @Value("${log.system.name}")
    private String systemName;

    public void insertEvalItemInfo(EvalItemInfo evalItemInfo ,String username){
        evalItemInfo.setEvalItemId(TimeHelper.getUniqueId(4));
        evalItemInfoMapper.insert(evalItemInfo);
        pubLogMapper.saveNoramlLogInfo(username,systemName, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
                String.format("删除报修单表单编号:{%s} 操作成功!", new Object[] {evalItemInfo.getEvalItemId()}),
                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_EVALUATE_MANAGEMENT.getMessage());
    }

    public void updateEvalItemInfo(EvalItemInfo evalItemInfo ,String username){
        evalItemInfoMapper.updateById(evalItemInfo);
        pubLogMapper.saveNoramlLogInfo(username,systemName, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
                String.format("删除报修单表单编号:{%s} 操作成功!", new Object[] {evalItemInfo.getEvalItemId()}),
                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_EVALUATE_MANAGEMENT.getMessage());
    }

    public void deleteEvalItemInfo(String evalItemId,String username){
        evalItemInfoMapper.deleteById(evalItemId);
        pubLogMapper.saveNoramlLogInfo(username,systemName, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_DELETE.getCode(),
                String.format("删除报修单表单编号:{%s} 操作成功!", new Object[] {evalItemId}),
                LogInfoDic.LOG_MODULAR_ENUM.EFOMS_EVALUATE_MANAGEMENT.getMessage());
    }

    public List<EvalItemInfo> getEvalItemList(String evalItemId){
        return evalItemInfoMapper.selectList(new EvalItemInfo(evalItemId,null,null));
    }

}
